package com.jxaummd.mushroom.main.common.fragment;


import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;


import com.jxaummd.mushroom.R;
import com.jxaummd.mushroom.R2;
import com.jxaummd.mushroom.core.base.fragment.PresenterFragment;
import com.jxaummd.mushroom.main.common.contract.SignUpSendCodeContract;
import com.jxaummd.mushroom.main.common.presenter.SignUpSendCodePresenter;

import butterknife.BindView;
import butterknife.OnClick;
import me.yokeyword.fragmentation.ISupportFragment;

public class SignUpSendCodeFragment extends PresenterFragment<SignUpSendCodeContract.Presenter>
        implements SignUpSendCodeContract.View {

    @BindView(R2.id.ec_et_common_signup_phonenumber)
    EditText mEditPhoneNumber = null;

    @BindView(R2.id.ec_tv_common_signup_contract_hint)
    TextView mTextContract = null;

    @OnClick(R2.id.ec_ib_common_signup_close)
    public void close() {
        pop();
    }

    @OnClick(R2.id.ec_btn_common_signup_get_testcode)
    public void sendTestcode() {
        mPresenter.sendCode(mEditPhoneNumber.getText().toString());
    }

    @Override
    protected SignUpSendCodeContract.Presenter initPresenter() {
        return new SignUpSendCodePresenter(this);
    }

    @Override
    public Object setLayout() {
        return R.layout.common_signup_sendcode;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {
        mPresenter.start();
    }

    @Override
    public void initText(SpannableString string) {
        mTextContract.setText("");
        mTextContract.setHighlightColor(Color.TRANSPARENT);
        mTextContract.append(string);
        mTextContract.setMovementMethod(LinkMovementMethod.getInstance());
    }

    @Override
    public void startNewFragment(ISupportFragment fragment) {
        hideSoftInput();
        if(fragment instanceof SignUpFragment){
            startWithPop(fragment);
        }else {
            start(fragment);
        }
    }

}
